<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AIfES 2: aifes_express_q7_fnn.h File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
</script>
<script type="text/javascript" async="async" src="https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="AIfES_logo_small.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">AIfES 2
   &#160;<span id="projectnumber">2.0.0</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('aifes__express__q7__fnn_8h.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">aifes_express_q7_fnn.h File Reference</div>  </div>
</div><!--header-->
<div class="contents">

<p>AIfES Express functions for weights with Q7 (int8) data type.  
<a href="#details">More...</a></p>

<p><a href="aifes__express__q7__fnn_8h_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ac543551279494c6ce9709e4ee6f59104"><td class="memItemLeft" align="right" valign="top">uint32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="aifes__express__q7__fnn_8h.html#ac543551279494c6ce9709e4ee6f59104">AIFES_E_flat_weights_number_fnn_q7</a> (uint32_t *fnn_structure, uint32_t layer_count)</td></tr>
<tr class="memdesc:ac543551279494c6ce9709e4ee6f59104"><td class="mdescLeft">&#160;</td><td class="mdescRight">Calculates the required length of the uint8_t array for the FNN.  <a href="aifes__express__q7__fnn_8h.html#ac543551279494c6ce9709e4ee6f59104">More...</a><br /></td></tr>
<tr class="separator:ac543551279494c6ce9709e4ee6f59104"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a0518e913814f0ab2f04f75f3d47c495e"><td class="memItemLeft" align="right" valign="top">int8_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="aifes__express__q7__fnn_8h.html#a0518e913814f0ab2f04f75f3d47c495e">AIFES_E_quantisation_fnn_f32_to_q7</a> (<a class="el" href="structaitensor.html">aitensor_t</a> *representative_f32_dataset, <a class="el" href="struct_a_i_f_e_s___e__model__parameter__fnn__f32.html">AIFES_E_model_parameter_fnn_f32</a> *AIFES_E_fnn, uint8_t *q7_parameter_dataset)</td></tr>
<tr class="memdesc:a0518e913814f0ab2f04f75f3d47c495e"><td class="mdescLeft">&#160;</td><td class="mdescRight">Quantizes the weights of an F32 FNN into a Q7 FNN.  <a href="aifes__express__q7__fnn_8h.html#a0518e913814f0ab2f04f75f3d47c495e">More...</a><br /></td></tr>
<tr class="separator:a0518e913814f0ab2f04f75f3d47c495e"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a2bf3d2e767a7a1d9bef8a1a179e7324a"><td class="memItemLeft" align="right" valign="top">int8_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="aifes__express__q7__fnn_8h.html#a2bf3d2e767a7a1d9bef8a1a179e7324a">AIFES_E_inference_fnn_q7</a> (<a class="el" href="structaitensor.html">aitensor_t</a> *input_tensor, <a class="el" href="struct_a_i_f_e_s___e__model__parameter__fnn__f32.html">AIFES_E_model_parameter_fnn_f32</a> *AIFES_E_fnn, <a class="el" href="structaitensor.html">aitensor_t</a> *output_tensor)</td></tr>
<tr class="memdesc:a2bf3d2e767a7a1d9bef8a1a179e7324a"><td class="mdescLeft">&#160;</td><td class="mdescRight">Executes the inference of a Q7 FNN.  <a href="aifes__express__q7__fnn_8h.html#a2bf3d2e767a7a1d9bef8a1a179e7324a">More...</a><br /></td></tr>
<tr class="separator:a2bf3d2e767a7a1d9bef8a1a179e7324a"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>AIfES Express functions for weights with Q7 (int8) data type. </p>
<dl class="section version"><dt>Version</dt><dd>2.2.0 </dd></dl>
<dl class="section copyright"><dt>Copyright</dt><dd>Copyright (C) 2020-2023 Fraunhofer Institute for Microelectronic Circuits and Systems. All rights reserved.<br  />
<br  />
 AIfES is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.<br  />
<br  />
 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.<br  />
<br  />
 You should have received a copy of the GNU Affero General Public License along with this program. If not, see <a href="https://www.gnu.org/licenses/">https://www.gnu.org/licenses/</a>.</dd></dl>
<p>AIfES Express is a beginner friendly high-level API of AIfES. This file contains all necessary functions for neural networks with int8 weights. </p>
</div><h2 class="groupheader">Function Documentation</h2>
<a id="ac543551279494c6ce9709e4ee6f59104"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ac543551279494c6ce9709e4ee6f59104">&#9670;&nbsp;</a></span>AIFES_E_flat_weights_number_fnn_q7()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">uint32_t AIFES_E_flat_weights_number_fnn_q7 </td>
          <td>(</td>
          <td class="paramtype">uint32_t *&#160;</td>
          <td class="paramname"><em>fnn_structure</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint32_t&#160;</td>
          <td class="paramname"><em>layer_count</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Calculates the required length of the uint8_t array for the FNN. </p>
<p>Contains the number of weights and additionally the necessary parameters for the fixpoint shifting</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">*fnn_structure</td><td>The FNN structure </td></tr>
    <tr><td class="paramname">layer_count</td><td>Number of layers </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Required length of the uint8_t array </dd></dl>

</div>
</div>
<a id="a2bf3d2e767a7a1d9bef8a1a179e7324a"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a2bf3d2e767a7a1d9bef8a1a179e7324a">&#9670;&nbsp;</a></span>AIFES_E_inference_fnn_q7()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int8_t AIFES_E_inference_fnn_q7 </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>input_tensor</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="struct_a_i_f_e_s___e__model__parameter__fnn__f32.html">AIFES_E_model_parameter_fnn_f32</a> *&#160;</td>
          <td class="paramname"><em>AIFES_E_fnn</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>output_tensor</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Executes the inference of a Q7 FNN. </p>
<p>Requires the input tensor, the FNN model parameters and an output tensor for the results. Use here as flat_weights the q7_parameter_dataset calculated from quantization The function takes float data as input tensor and converts it to Q7 format. The inference is performed with the Q7 FNN. For the output, the results are again converted as float and output via the output tensor.</p>
<p>Possible returns:</p><ul>
<li>0 = success</li>
<li>1 = ERROR! Tensor dtype</li>
<li>2 = ERROR! Tensor shape: Data Number</li>
<li>3 = ERROR! Input tensor shape does not correspond to ANN inputs</li>
<li>4 = ERROR! Output tensor shape does not correspond to ANN outputs</li>
<li>5 = ERROR! Unknown activation function</li>
<li>6 = ERROR! Not enough memory</li>
</ul>
<p><b>Example:</b> </p><div class="fragment"><div class="line">uint32_t nn_structure[3] = {2,3,1};</div>
<div class="line"> </div>
<div class="line"><a class="code" href="aifes__express__f32__fnn_8h.html#a6dad88532ecc9bc7786bb69c0aab7c23">AIFES_E_activations</a> nn_activations[2];</div>
<div class="line">nn_activations[0] = <a class="code" href="aifes__express__f32__fnn_8h.html#a6dad88532ecc9bc7786bb69c0aab7c23a68c5b8166b0ec1f39f3f66eae44907d6">AIfES_E_sigmoid</a>;</div>
<div class="line">nn_activations[1] = <a class="code" href="aifes__express__f32__fnn_8h.html#a6dad88532ecc9bc7786bb69c0aab7c23a68c5b8166b0ec1f39f3f66eae44907d6">AIfES_E_sigmoid</a>;</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Q7 weights (4 byte aligned: AIFES_MEMORY_ALIGNMENT = 4)</span></div>
<div class="line">uint32_t weights_q7[ 16 ] = {</div>
<div class="line">    0x00BA0007, 0x00290003, 0x000B0003, 0x00000003, 0x3A2CBDAF, 0x0000B8C3, 0x0000000A, 0x00000000, 0xFFFFF424, 0x00000979,</div>
<div class="line">    0xFFFFF99D, 0x00000003, 0x005FCB60, 0x0000000B, 0x00000000, 0xFFFFD49A</div>
<div class="line">};</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Q7 weights (2 byte aligned: AIFES_MEMORY_ALIGNMENT = 2)</span></div>
<div class="line"><span class="comment">//uint16_t weights_q7[ 29 ] = {</span></div>
<div class="line"><span class="comment">//    0x0007, 0x00BA, 0x0003, 0x0029, 0x0003, 0x000B, 0x0003, 0x0000, 0xBDAF, 0x3A2C, 0xB8C3, 0x000A, 0x0000, 0x0000, 0xF424, 0xFFFF,</span></div>
<div class="line"><span class="comment">//    0x0979, 0x0000, 0xF99D, 0xFFFF, 0x0003, 0x0000, 0xCB60, 0x005F, 0x000B, 0x0000, 0x0000, 0xD49A, 0xFFFF</span></div>
<div class="line"><span class="comment">//};</span></div>
<div class="line"> </div>
<div class="line"><a class="code" href="struct_a_i_f_e_s___e__model__parameter__fnn__f32.html">AIFES_E_model_parameter_fnn_f32</a> nn;</div>
<div class="line">nn.<a class="code" href="struct_a_i_f_e_s___e__model__parameter__fnn__f32.html#a7c6673fb07eaacde14fefa8739cf81d9">layer_count</a> = 3;</div>
<div class="line">nn.<a class="code" href="struct_a_i_f_e_s___e__model__parameter__fnn__f32.html#ac0e27d2721e3fc56a5271daa70a1c4cf">fnn_structure</a> = nn_structure;</div>
<div class="line">nn.<a class="code" href="struct_a_i_f_e_s___e__model__parameter__fnn__f32.html#ac19fe5a39b6c6c68774d040417741b5c">fnn_activations</a> = nn_activations;</div>
<div class="line">nn.<a class="code" href="struct_a_i_f_e_s___e__model__parameter__fnn__f32.html#a4c8ac1a2e6acb80433ed33dafe5e703d">flat_weights</a> = weights_q7;</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">float</span> input_data[4][2] = {</div>
<div class="line">    {0.0f, 0.0f},</div>
<div class="line">    {0.0f, 1.0f},</div>
<div class="line">    {1.0f, 0.0f},</div>
<div class="line">    {1.0f, 1.0f}</div>
<div class="line">};</div>
<div class="line">uint16_t input_shape[4*2] = {4, 2};                     <span class="comment">// Definition of the input shape</span></div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> input_tensor = AITENSOR_2D_F32(input_shape, input_data);                 <span class="comment">// Macro for the simple creation of a float32 tensor. Also usable in the normal AIfES version</span></div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">float</span> output_data[4*1];                                                        <span class="comment">// Output data</span></div>
<div class="line">uint16_t output_shape[] = {4, 1};</div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> output_tensor = AITENSOR_2D_F32(output_shape, output_data);</div>
<div class="line"> </div>
<div class="line">int8_t error;</div>
<div class="line">error = <a class="code" href="aifes__express__q7__fnn_8h.html#a2bf3d2e767a7a1d9bef8a1a179e7324a">AIFES_E_inference_fnn_q7</a>(&amp;input_tensor,</div>
<div class="line">                                 &amp;nn,</div>
<div class="line">                                 &amp;output_tensor);</div>
<div class="ttc" id="aaifes__express__f32__fnn_8h_html_a6dad88532ecc9bc7786bb69c0aab7c23"><div class="ttname"><a href="aifes__express__f32__fnn_8h.html#a6dad88532ecc9bc7786bb69c0aab7c23">AIFES_E_activations</a></div><div class="ttdeci">AIFES_E_activations</div><div class="ttdoc">Possible activation functions in AIfES-Express.</div><div class="ttdef"><b>Definition:</b> aifes_express_f32_fnn.h:34</div></div>
<div class="ttc" id="aaifes__express__f32__fnn_8h_html_a6dad88532ecc9bc7786bb69c0aab7c23a68c5b8166b0ec1f39f3f66eae44907d6"><div class="ttname"><a href="aifes__express__f32__fnn_8h.html#a6dad88532ecc9bc7786bb69c0aab7c23a68c5b8166b0ec1f39f3f66eae44907d6">AIfES_E_sigmoid</a></div><div class="ttdeci">@ AIfES_E_sigmoid</div><div class="ttdoc">Sigmoid.</div><div class="ttdef"><b>Definition:</b> aifes_express_f32_fnn.h:36</div></div>
<div class="ttc" id="aaifes__express__q7__fnn_8h_html_a2bf3d2e767a7a1d9bef8a1a179e7324a"><div class="ttname"><a href="aifes__express__q7__fnn_8h.html#a2bf3d2e767a7a1d9bef8a1a179e7324a">AIFES_E_inference_fnn_q7</a></div><div class="ttdeci">int8_t AIFES_E_inference_fnn_q7(aitensor_t *input_tensor, AIFES_E_model_parameter_fnn_f32 *AIFES_E_fnn, aitensor_t *output_tensor)</div><div class="ttdoc">Executes the inference of a Q7 FNN.</div></div>
<div class="ttc" id="astruct_a_i_f_e_s___e__model__parameter__fnn__f32_html"><div class="ttname"><a href="struct_a_i_f_e_s___e__model__parameter__fnn__f32.html">AIFES_E_model_parameter_fnn_f32</a></div><div class="ttdoc">Parameters for the FNN model.</div><div class="ttdef"><b>Definition:</b> aifes_express_f32_fnn.h:107</div></div>
<div class="ttc" id="astruct_a_i_f_e_s___e__model__parameter__fnn__f32_html_a4c8ac1a2e6acb80433ed33dafe5e703d"><div class="ttname"><a href="struct_a_i_f_e_s___e__model__parameter__fnn__f32.html#a4c8ac1a2e6acb80433ed33dafe5e703d">AIFES_E_model_parameter_fnn_f32::flat_weights</a></div><div class="ttdeci">void * flat_weights</div><div class="ttdoc">Pointer to the array with the weights.</div><div class="ttdef"><b>Definition:</b> aifes_express_f32_fnn.h:111</div></div>
<div class="ttc" id="astruct_a_i_f_e_s___e__model__parameter__fnn__f32_html_a7c6673fb07eaacde14fefa8739cf81d9"><div class="ttname"><a href="struct_a_i_f_e_s___e__model__parameter__fnn__f32.html#a7c6673fb07eaacde14fefa8739cf81d9">AIFES_E_model_parameter_fnn_f32::layer_count</a></div><div class="ttdeci">uint32_t layer_count</div><div class="ttdoc">Count of all layers, including input and output layers.</div><div class="ttdef"><b>Definition:</b> aifes_express_f32_fnn.h:108</div></div>
<div class="ttc" id="astruct_a_i_f_e_s___e__model__parameter__fnn__f32_html_ac0e27d2721e3fc56a5271daa70a1c4cf"><div class="ttname"><a href="struct_a_i_f_e_s___e__model__parameter__fnn__f32.html#ac0e27d2721e3fc56a5271daa70a1c4cf">AIFES_E_model_parameter_fnn_f32::fnn_structure</a></div><div class="ttdeci">uint32_t * fnn_structure</div><div class="ttdoc">Pointer to the network structure.</div><div class="ttdef"><b>Definition:</b> aifes_express_f32_fnn.h:109</div></div>
<div class="ttc" id="astruct_a_i_f_e_s___e__model__parameter__fnn__f32_html_ac19fe5a39b6c6c68774d040417741b5c"><div class="ttname"><a href="struct_a_i_f_e_s___e__model__parameter__fnn__f32.html#ac19fe5a39b6c6c68774d040417741b5c">AIFES_E_model_parameter_fnn_f32::fnn_activations</a></div><div class="ttdeci">AIFES_E_activations * fnn_activations</div><div class="ttdoc">Pointer to the activation function list (AIFES_E_activations)</div><div class="ttdef"><b>Definition:</b> aifes_express_f32_fnn.h:110</div></div>
<div class="ttc" id="astructaitensor_html"><div class="ttname"><a href="structaitensor.html">aitensor</a></div><div class="ttdoc">A tensor in AIfES.</div><div class="ttdef"><b>Definition:</b> aifes_math.h:89</div></div>
</div><!-- fragment --><dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">*input_tensor</td><td>Tensor with the inputs </td></tr>
    <tr><td class="paramname">*AIFES_E_fnn</td><td>The FNN model parameters </td></tr>
    <tr><td class="paramname">*output_tensor</td><td>Tensor for the results </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Error output </dd></dl>

</div>
</div>
<a id="a0518e913814f0ab2f04f75f3d47c495e"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a0518e913814f0ab2f04f75f3d47c495e">&#9670;&nbsp;</a></span>AIFES_E_quantisation_fnn_f32_to_q7()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int8_t AIFES_E_quantisation_fnn_f32_to_q7 </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>representative_f32_dataset</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="struct_a_i_f_e_s___e__model__parameter__fnn__f32.html">AIFES_E_model_parameter_fnn_f32</a> *&#160;</td>
          <td class="paramname"><em>AIFES_E_fnn</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint8_t *&#160;</td>
          <td class="paramname"><em>q7_parameter_dataset</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Quantizes the weights of an F32 FNN into a Q7 FNN. </p>
<p>The representative dataset should cover the min max values of the inputs. The dataset is needed for the calculation of the shift and the zero point of each layer.</p>
<p>** The Q7 quantized buffer can only be used with architectures with the same AIFES_MEMORY_ALIGNMENT. The inference might crash if you export the buffer to architectures with different AIFES_MEMORY_ALIGNMENT. **</p>
<p>Possible returns:</p><ul>
<li>0 = success</li>
<li>1 = ERROR! Tensor dtype</li>
<li>2 = ERROR! Input tensor shape does not correspond to ANN inputs</li>
<li>3 = ERROR! Not enough memory</li>
<li>4 = ERROR! Unknown activation function</li>
</ul>
<p><b>Example:</b> </p><div class="fragment"><div class="line">uint32_t nn_structure[3] = {2,3,1};</div>
<div class="line"> </div>
<div class="line"><a class="code" href="aifes__express__f32__fnn_8h.html#a6dad88532ecc9bc7786bb69c0aab7c23">AIFES_E_activations</a> nn_activations[2];</div>
<div class="line">nn_activations[0] = <a class="code" href="aifes__express__f32__fnn_8h.html#a6dad88532ecc9bc7786bb69c0aab7c23a68c5b8166b0ec1f39f3f66eae44907d6">AIfES_E_sigmoid</a>;</div>
<div class="line">nn_activations[1] = <a class="code" href="aifes__express__f32__fnn_8h.html#a6dad88532ecc9bc7786bb69c0aab7c23a68c5b8166b0ec1f39f3f66eae44907d6">AIfES_E_sigmoid</a>;</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">float</span> weights[] = {-10.1164f, -8.4212f, 5.4396f, 7.297f, -7.6482f, -9.0155f, -2.9653f,</div>
<div class="line">                    2.3677f, -1.5968f, 12.0305f, -6.5858f, 11.9371f,-5.4247f};</div>
<div class="line"> </div>
<div class="line"><a class="code" href="struct_a_i_f_e_s___e__model__parameter__fnn__f32.html">AIFES_E_model_parameter_fnn_f32</a> nn;</div>
<div class="line">nn.<a class="code" href="struct_a_i_f_e_s___e__model__parameter__fnn__f32.html#a7c6673fb07eaacde14fefa8739cf81d9">layer_count</a> = 3;</div>
<div class="line">nn.<a class="code" href="struct_a_i_f_e_s___e__model__parameter__fnn__f32.html#ac0e27d2721e3fc56a5271daa70a1c4cf">fnn_structure</a> = nn_structure;</div>
<div class="line">nn.<a class="code" href="struct_a_i_f_e_s___e__model__parameter__fnn__f32.html#ac19fe5a39b6c6c68774d040417741b5c">fnn_activations</a> = nn_activations;</div>
<div class="line">nn.<a class="code" href="struct_a_i_f_e_s___e__model__parameter__fnn__f32.html#a4c8ac1a2e6acb80433ed33dafe5e703d">flat_weights</a> = weights;</div>
<div class="line"> </div>
<div class="line">uint32_t q7_parameter_memory_size = <a class="code" href="aifes__express__q7__fnn_8h.html#ac543551279494c6ce9709e4ee6f59104">AIFES_E_flat_weights_number_fnn_q7</a>(nn_structure, 3);</div>
<div class="line">uint8_t *weights_q7 = (uint8_t *) malloc(q7_parameter_memory_size);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// AIfES Express function: do the quantisation</span></div>
<div class="line"><a class="code" href="aifes__express__q7__fnn_8h.html#a0518e913814f0ab2f04f75f3d47c495e">AIFES_E_quantisation_fnn_f32_to_q7</a>(&amp;input_tensor,</div>
<div class="line">                                   &amp;nn,</div>
<div class="line">                                   weights_q7);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Change the flat weights for q7 calculation</span></div>
<div class="line">nn.<a class="code" href="struct_a_i_f_e_s___e__model__parameter__fnn__f32.html#a4c8ac1a2e6acb80433ed33dafe5e703d">flat_weights</a> = weights_q7;</div>
<div class="ttc" id="aaifes__express__q7__fnn_8h_html_a0518e913814f0ab2f04f75f3d47c495e"><div class="ttname"><a href="aifes__express__q7__fnn_8h.html#a0518e913814f0ab2f04f75f3d47c495e">AIFES_E_quantisation_fnn_f32_to_q7</a></div><div class="ttdeci">int8_t AIFES_E_quantisation_fnn_f32_to_q7(aitensor_t *representative_f32_dataset, AIFES_E_model_parameter_fnn_f32 *AIFES_E_fnn, uint8_t *q7_parameter_dataset)</div><div class="ttdoc">Quantizes the weights of an F32 FNN into a Q7 FNN.</div></div>
<div class="ttc" id="aaifes__express__q7__fnn_8h_html_ac543551279494c6ce9709e4ee6f59104"><div class="ttname"><a href="aifes__express__q7__fnn_8h.html#ac543551279494c6ce9709e4ee6f59104">AIFES_E_flat_weights_number_fnn_q7</a></div><div class="ttdeci">uint32_t AIFES_E_flat_weights_number_fnn_q7(uint32_t *fnn_structure, uint32_t layer_count)</div><div class="ttdoc">Calculates the required length of the uint8_t array for the FNN.</div></div>
</div><!-- fragment --><dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">*representative_f32_dataset</td><td>Tensor with the inputs </td></tr>
    <tr><td class="paramname">*AIFES_E_fnn</td><td>The FNN model parameters </td></tr>
    <tr><td class="paramname">*q7_parameter_dataset</td><td>Tensor for the results </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Error output </dd></dl>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li><li class="navelem"><a class="el" href="dir_1e5d3661ed79af157d57e64a38265d09.html">basic</a></li><li class="navelem"><a class="el" href="dir_d248cdab09ece91db2a68dd96cc4ef4f.html">express</a></li><li class="navelem"><a class="el" href="aifes__express__q7__fnn_8h.html">aifes_express_q7_fnn.h</a></li>
    <li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.1 </li>
  </ul>
</div>
</body>
</html>
